<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i>
                    {{pageTitle}}
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="table-form-box">
                <h3 class="h3">考核模板详情</h3>

                <table border="0" width="100%" cellpadding="0" cellspacing="1">
                    <tbody>
                        <tr>
                            <td align="right">
                                <span class="color-ff2200">*</span>考核类别:
                            </td>
                            <td>{{formData.templateTypeName}}</td>
                            <td align="right">
                                <span class="color-ff2200">*</span>模板名称:
                            </td>
                            <td>{{formData.templateName}}</td>
                            <td align="right">创建人:</td>
                            <td>{{formData.createUserName}}</td>
                        </tr>
                    </tbody>
                </table>

                <div style="margin-top:10px;border:1px solid">
                    <div style="margin:10px;">
                        <vxe-table
                            keep-source
                            stripe
                            border
                            show-footer
                            :footer-method="footerMethod"
                            resizable
                            ref="xTable"
                            :data="tableData"
                        >
                            <vxe-table-column type="checkbox" width="60"></vxe-table-column>
                            <vxe-table-column type="seq" width="60"></vxe-table-column>
                            <vxe-table-column
                                field="itemName"
                                title="考核项"
                                :edit-render="{name: 'input', attrs: {type: 'text'}}"
                            ></vxe-table-column>
                            <vxe-table-column
                                field="points"
                                title="分数"
                                :edit-render="{name: '$input', props: {type: 'number',min:0,max:999}}"
                            ></vxe-table-column>
                            <vxe-table-column
                                field="description"
                                title="考核说明"
                                :edit-render="{name: 'input', attrs: {type: 'text'}}"
                            ></vxe-table-column>
                            <vxe-table-column title="自评分数"></vxe-table-column>
                            <vxe-table-column title="上级评分"></vxe-table-column>
                        </vxe-table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import appMain from '../../../utils/app_main';
import XEUtils from 'xe-utils';
export default {
    name: 'transfer',
    data() {
        return {
            pageTitle: '',
            formData: {
                assessmentPoints: '', //总分
                templateName: '', //福利编码
                templateTypeId: '', //模板类型
                templateTypeName: '', //模板类型名称
                templateTypeValue: '', //模板类型
                createUserName: '',
                createUserId: '',
                assessmentItemDTOList: [] //考核项信息
            },
            isEdit: false,
            editId: '',

            tableData: []
        };
    },
    created() {
        // 如果有id就是跳转过来修改的
        if (this.$route.query.id) {
            this.editId = this.$route.query.id;
            this.isEdit = true;
            this.getData(); // 获取要修改的数据
        } else {
            this.$router.push({
                path: '/assessmentList' //跳转的路径
            });
        }
    },
    methods: {
        getData() {
            appMain
                .assessmentTemplateFindById({}, this.editId)
                .then(res => {
                    if (res.data.code === 20000) {
                        this.formData = res.data.data;
                        this.tableData = res.data.data.assessmentItemDTOList;
                        //获取人员档案附件
                        //this.uploadFileInfoFindById(this.formData.id);
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //表脚
        footerMethod({ columns, data }) {
            return [
                columns.map((column, columnIndex) => {
                    if (columnIndex === 0) {
                        return '合计';
                    }
                    if (columnIndex === 3) {
                        //console.log('columns', data);
                        let coin = `${XEUtils.sum(data, 'points')}`;
                        this.formData.assessmentPoints = coin;
                        return '考核总分:' + coin + ' 分';
                    }
                    return '-';
                })
            ];
        }
    },
    mounted() {
        this.pageTitle = this.$router.currentRoute.meta.title;
    }
};
</script>

<style scoped>
.container {
    padding-bottom: 50px;
}
.handle-box {
    padding: 5px 50px;
    width: 100%;
    background-color: #fff;
    position: absolute;
    left: 0;
    bottom: 0px;
    border-bottom: 1px solid #ddd;
    border-top: 1px solid #ddd;
    z-index: 1;
}

.table {
    width: 100%;
    font-size: 14px;
}

.table-form-box table {
    background-color: #666;
}
.table-form-box .h3 {
    font-size: 22px;
    text-align: center;
    font-weight: normal;
    padding: 20px 0;
}
.table-form-box table .tr-title td {
    font-size: 14px;
    line-height: 40px;
}
.table-form-box table td {
    background-color: #fff;
    padding: 4px;
    min-height: 40px;
    font-size: 14px;
}
.table-form-box table th {
    background-color: #fff;
    padding: 4px;
    min-height: 40px;
    font-size: 14px;
    font-weight: bold;
}
.color-ff2200 {
    color: #ff2200;
}
</style>
